module(..., package.seeall)
local _W,_H = display.contentWidth,display.contentHeight
local b_width = 100
local b_height = 100
local game_link = "images/game/"
local sound_link = "sound/"

function newButton(params)
	local buttonGroup = display.newGroup()
	local button = display.newImageRect(game_link.."button_Circle.png",b_width,b_height)
	button.x = params.x
	button.y = params.y
	button.id = params.id
	buttonGroup:insert(button)
	local button2 = display.newImageRect(game_link.."button2_Circle.png",b_width,b_height)
	button2.x = params.x
	button2.y = params.y
	button2.id = params.id
	button2.alpha = 0
	button2:addEventListener("touch",button2)
	buttonGroup:insert(button2)

	button.touch = function(self,event)
		if self then
			local phase = event.phase
				if ( phase == "began" ) then
					display.getCurrentStage():setFocus( button2 )
					button.alpha = 0
					button2.alpha = 1
				end
			return true
		end
	end
	button2.touch = function(button2,event)
		if button2 then
			local phase = event.phase
				if( phase == "ended" or  phase == "cancel") then
					display.getCurrentStage():setFocus( button1 )
					button.alpha = 1
					button2.alpha = 0
				end
			return true
		end
	end

	function button:init()
		self.status = "stand"
		self:startListener()
	end

	function button:startListener()
		self:addEventListener("touch",self)
	end

	function button:stopListener()
		self:removeEventListener("touch",self)
--		button2:removeEventListener("touch",button2)
		button.alpha = 1
		button2.alpha = 0
	end

	return button
end